package com.ruge._08_springboot_springdata_jpa.controller._02_entityManager;

import com.ruge._08_springboot_springdata_jpa.Application;
import com.ruge._08_springboot_springdata_jpa.model.base.BaseModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;

/**
 * 创建人 ：爱丽丝、如歌
 * 创建时间 ：2019-07-05  22:43
 * 描述 ：junit 数据增加测试
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)//这里是启动类
public class TestInsert {
    @Autowired
    private EntityManager entityManager;

    @Test
    @Transactional
    public void test() {
        BaseModel model = new BaseModel();
        model.setUserName("张三"+Math.random());
        //保存数据
        entityManager.persist(model);
        entityManager.flush();
        System.out.println("==================");
    }
}
